#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=5100;
struct Line
{
	int x,y1,y2,flag;
	bool friend operator<(Line a,Line b)
	{
		return a.x<b.x;
	}
}line[maxn*2];
struct node
{
	int left,right,lf,ri,len,lbd,rbd,line,cov;
}tree[maxn*8];
int y[maxn*2];
int aabs(int x)
{
	if(x<0)return x*-1;
	return x;
}
void pushUp(int u)
{
	if(tree[u].left+1==tree[u].right)
		tree[u].len=tree[u].lbd=tree[u].rbd=tree[u].line=0;
	else
	{
		tree[u].len=tree[u*2].len+tree[u*2+1].len;
		tree[u].lbd=tree[u*2].lbd;
		tree[u].rbd=tree[u*2+1].rbd;
		if(tree[u*2].rbd&&tree[u*2+1].lbd)
			tree[u].line=tree[u*2].line+tree[u*2+1].line-1;
		else
			tree[u].line=tree[u*2].line+tree[u*2+1].line;
	}
}
void build(int L,int R,int u)
{
	tree[u].left=L;
	tree[u].right=R;
	tree[u].lf=y[L];
	tree[u].ri=y[R];
	tree[u].cov=tree[u].len=tree[u].line=tree[u].rbd=tree[u].lbd=0;
	if(L+1==R)return ;
	int mid=(L+R)/2;
	build(L,mid,u*2);
	build(mid,R,u*2+1);
}
void update(int u,Line e)
{
	if(e.y1<=tree[u].lf&&e.y2>=tree[u].ri)
	{
		if(e.flag==1)
		{
			tree[u].len=tree[u].ri-tree[u].lf;
			tree[u].cov++;
			tree[u].lbd=tree[u].rbd=tree[u].line=1;
		}
		else
		{
			tree[u].cov--;
			if(tree[u].cov==0)
				pushUp(u);	
		}		
		return ;
	}
	if(e.y1<tree[u*2].ri)update(u*2,e);
	if(e.y2>tree[u*2+1].lf)update(u*2+1,e);
	if(tree[u].cov==0)pushUp(u);		
}


int main()
{
	int n;
	scanf("%d",&n);
	int t=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		int x1,x2,y1,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		t++;
		line[t].x=x1;
		line[t].y1=y1;
		line[t].y2=y2;
		line[t].flag=1;
		y[t]=y1;
		t++;
		line[t].x=x2;
		line[t].y1=y1;
		line[t].y2=y2;
		line[t].flag=-1;
		y[t]=y2;
	}
	sort(line+1,line+1+t);
	sort(y+1,y+t+1);
	build(1,t,1);
	update(1,line[1]);
	ans+=tree[1].len;
	for(int i=2;i<=t;i++)
	{
		ans+=(tree[1].line*2)*(line[i].x-line[i-1].x);
		int tem=tree[1].len;
		update(1,line[i]);
		ans+=aabs(tree[1].len-tem);
	}
	printf("%d\n",ans);
	return 0;
}



